﻿Imports System.IO
Imports System.Data.OleDb

Public Class ctrDuLieu

    Private Sub ShowTab()
        Dim i As Integer = frmMain.TabControl1.TabCount - 1
        frmMain.TabControl1.SelectTab(i)
    End Sub

    Private Function ExistsTab(ByVal str As String) As Integer
        For i = 0 To frmMain.TabControl1.TabCount() - 1 Step 1
            If (frmMain.TabControl1.TabPages(i).Text = str) Then
                Return i
            End If
        Next
        Return -1
    End Function

    Private Sub btnBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackup.Click
        btnImport.ForeColor = Color.Blue
        btnImport.BackColor = Color.White
        btnBackup.ForeColor = Color.White
        btnBackup.BackColor = Color.Blue
        btnExportExcel.ForeColor = Color.Blue
        btnExportExcel.BackColor = Color.White

        Dim str As String = "Sao lưu dữ liệu"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrSaoLuu = New ctrSaoLuu()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If

        'Dim f As FileInfo = New FileInfo("D:\VB.NET\Database\QLNH.mdb")
        'f.CopyTo("D:\QLNH" + Now.ToString("_yyyy_MM_dd_hh_mm") + ".mdb")
    End Sub

    Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportExcel.Click
        btnImport.ForeColor = Color.Blue
        btnImport.BackColor = Color.White
        btnBackup.ForeColor = Color.Blue
        btnBackup.BackColor = Color.White
        btnExportExcel.ForeColor = Color.White
        btnExportExcel.BackColor = Color.Blue

        Dim str As String = "Truy xuất dữ liệu"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrTruyXuat = New ctrTruyXuat()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        btnImport.ForeColor = Color.White
        btnImport.BackColor = Color.Blue
        btnBackup.ForeColor = Color.Blue
        btnBackup.BackColor = Color.White
        btnExportExcel.ForeColor = Color.Blue
        btnExportExcel.BackColor = Color.White

        Dim str As String = "Kết nối dữ liệu"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrKetNoi = New ctrKetNoi()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If
    End Sub
End Class
